Ext.define('PJ.view.trainingprogram.ParticipantsNumList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.participantsNumList'],
    requires: [],
    isHavePage: false,
    selModel: {
	        selType: '',
	        // 设置为只能通过复选框选中行
	        checkOnly: true
	    },
	myRowIndex: null,
	myID: null,
	res: null,
    initComponent: function(){
    	var me= this;
    	var versionState = me.versionState;
    	var columns = [{
    	               header: '单位名称',
    	               dataIndex: 'contrastObject',
    	               flex: 1,
    	               align: "center",
    	               sortable: false,
    	       		renderer: function(value, metaData, record){
    	       			metaData.tdAttr = 'data-qtip="' + value + '"';
    	       			if(record.get("unitNameStatus") && versionState){
    	       				metaData.style = "color:red;";
    	       			}
    	       			return value;
    	       		}
    	           },{
    	           	header: '计划市级人数',
    	           	dataIndex: 'contrastCityValue',
    	               minWidth: 90,
    	               flex: 1,
    	               align: "center",
    	               sortable: false,
    	       		renderer: function(value, metaData, record, rowIndex, colIndex){
    	       			if(record.get("contrastObject") == "合计"){
    	       				metaData.style = "white-space:normal;";
    	       			}else {
    	       				metaData.style = "white-space:normal;cursor: pointer;";
    	       			}
    	       			metaData.tdAttr ="rowIndex=" + rowIndex + " contrastCityValue=" + (value || 0) + " objectID=" + record.get("objectID") + " id=contrastCityValue_" + record.get("objectID") + " contrastObject=" + record.get("contrastObject") + " thisTotal=" + (record.get("contrastCountValue") || 0) + " contrastCountyValue=" + (record.get("contrastCountyValue") || 0);
    	       			if(!record.get("contrastCityState") && versionState){
    	       				if(record.get("contrastObject") == "合计"){
    	       					metaData.style = "white-space:normal;color:red;";
        	       			}else {
        	       				metaData.style = "white-space:normal;cursor: pointer;color:red;";
        	       			}
    	       			}
    	       			return value || 0;
    	       		},
    	       		listeners: {
    	       			click: function(g, clm){
    	       				if(clm.getAttribute("contrastObject") == "合计"){
    	       					return;
    	       				}else{
    	       					me.myRowIndex = clm.getAttribute("rowIndex");
        	       				me.myID = clm.getAttribute("objectID");
        	       				var firstValue = me.res[Number(clm.getAttribute("rowIndex"))].contrastCityValue || 0;
        	       				var firstTotal = me.res[Number(clm.getAttribute("rowIndex"))].contrastCountValue || 0;
        	       				var firstValueOther = me.res[Number(clm.getAttribute("rowIndex"))].contrastCountyValue || 0;
        	       				var totalNumber = me.res[0].contrastCityValue || 0;
        	       				var contrastCountyValueTotal = me.res[0].contrastCountyValue || 0;
        	       				var contrastCityValueTotal = me.res[0].contrastCityValue || 0;
        	       				Ext.create('PJ.view.trainingprogram.PNEdit',{
        	       		        	title: "更新" + clm.getAttribute("contrastObject") + "市级人数",
        	       		            flag:1,
        	       		        	grid: me,
        	       		        	myRowIndex:clm.getAttribute("rowIndex"),
        	       		        	myID:clm.getAttribute("objectID"),
        	       		        	thisValue: clm.getAttribute("contrastCityValue"),
        	       		        	firstValue: firstValue,
        	       		        	firstTotal: firstTotal,
        	       		        	thisTotal: clm.getAttribute("thisTotal"),
        	       		        	contrastCountyValue: clm.getAttribute("contrastCountyValue"),
        	       		        	totalNumber: totalNumber,
        	       		        	contrastCountyValueTotal: contrastCountyValueTotal,
        	       		        	firstValueOther: firstValueOther,
        	       		        	contrastCityValueTotal: contrastCityValueTotal
        	       		        });
    	       				}
    	       			}
    	       		}
    	           },{
    	           	header: '计划县级人数',
    	           	dataIndex: 'contrastCountyValue',
		               minWidth: 90,
		               flex: 1,
		               align: "center",
		               sortable: false,
    	       		renderer: function(value, metaData, record, rowIndex, colIndex){
    	       			if(record.get("contrastObject") == "合计"){
    	       				metaData.style = "white-space:normal;";
    	       			}else {
    	       				metaData.style = "white-space:normal;cursor: pointer;";
    	       			}
    	       			metaData.tdAttr ="rowIndex=" + rowIndex + " contrastCountyValue=" + (value || 0) + " objectID=" + record.get("objectID") + " id=contrastCountyValue_" + record.get("objectID") + " contrastObject=" + record.get("contrastObject") + " thisTotal=" + (record.get("contrastCountValue") || 0) + " contrastCityValue=" + (record.get("contrastCityValue") || 0);
    	       			if(!record.get("contrastCountyState") && versionState){
    	       				if(record.get("contrastObject") == "合计"){
    	       					metaData.style = "white-space:normal;color:red;";
        	       			}else {
        	       				metaData.style = "white-space:normal;cursor: pointer;color:red;";
        	       			}
    	       			}
    	       			return value || 0;
    	       		},
    	       		listeners: {
    	       			click: function(g, clm){
    	       				if(clm.getAttribute("contrastObject") == "合计"){
    	       					return;
    	       				}else {
    	       					me.myRowIndex = clm.getAttribute("rowIndex");
        	       				me.myID = clm.getAttribute("objectID");
        	       				var firstValue = me.res[Number(clm.getAttribute("rowIndex"))].contrastCountyValue || 0;
        	       				var firstTotal = me.res[Number(clm.getAttribute("rowIndex"))].contrastCountValue || 0;
        	       				var firstValueOther = me.res[Number(clm.getAttribute("rowIndex"))].contrastCityValue || 0;
        	       				var contrastCountyValueTotal = me.res[0].contrastCountValue || 0;
        	       				var totalNumber = me.res[0].contrastCountyValue || 0;
        	       				var contrastCityValueTotal = me.res[0].contrastCityValue || 0;
        	       				Ext.create('PJ.view.trainingprogram.PNEdit',{
        	       		        	title: "更新" + clm.getAttribute("contrastObject") + "县级人数",
        	       		            flag:2,
        	       		        	grid: me,
        	       		        	myRowIndex:clm.getAttribute("rowIndex"),
        	       		        	myID:clm.getAttribute("objectID"),
        	       		        	thisValue: clm.getAttribute("contrastCountyValue"),
        	       		        	firstValue: firstValue,
        	       		        	thisTotal: clm.getAttribute("thisTotal"),
        	       		        	firstTotal: firstTotal,
        	       		        	contrastCityValue: clm.getAttribute("contrastCityValue"),
        	       		        	totalNumber: totalNumber,
        	       		        	contrastCountyValueTotal: contrastCountyValueTotal,
        	       		        	firstValueOther: firstValueOther,
        	       		        	contrastCityValueTotal: contrastCityValueTotal
        	       		        });
    	       				}
    	       			}
    	       		}
    	           },{
    	           	header: '计划总人数',
    	           	dataIndex: 'contrastCountValue',
    	               minWidth: 90,
    	               flex: 1,
    	               align: "center",
    	               sortable: false,
    	       		renderer: function(value, metaData, record, rowIndex, colIndex){
    	       			metaData.style = "white-space:normal;";
    	       			metaData.tdAttr ="rowIndex=" + rowIndex + " contrastCountValue=" + (value || 0) + " objectID=" + record.get("objectID") + " id=contrastCountValue_" + record.get("objectID") + " contrastObject=" + record.get("contrastObject");
    	       			if(!record.get("contrastCountState") && versionState){
    	       				metaData.style = "white-space:normal;color:red;";
    	       			}
    	       			return value || 0;
    	       		}/*,
    	       		listeners: {
    	       			click: function(g, clm){
    	       				me.myRowIndex = clm.getAttribute("rowIndex");
    	       				me.myID = clm.getAttribute("objectID");
    	       				var firstValue = me.res[Number(clm.getAttribute("rowIndex"))].contrastCountValue;
    	       				Ext.create('PJ.view.trainingprogram.PNEdit',{
    	       		        	title: "更新" + clm.getAttribute("contrastObject") + "计划总人数",
    	       		            flag:3,
    	       		        	grid: me,
    	       		        	myRowIndex:clm.getAttribute("rowIndex"),
    	       		        	myID:clm.getAttribute("objectID"),
    	       		        	thisValue: clm.getAttribute("contrastCountValue"),
    	       		        	firstValue: firstValue
    	       		        });
    	       			}
    	       		}*/
    	           }];
    	if(me.isView){
    		columns = [{
		               header: '单位名称',
		               dataIndex: 'contrastObject',
		               flex: 1,
		               align: "center",
		               sortable: false,
		       		renderer: function(value, metaData, record){
		       			metaData.tdAttr = 'data-qtip="' + value + '"';
		       			if(record.get("unitNameStatus")){
		       				metaData.style = "color:red;";
		       			}
		       			return value;
		       		}
		           },{
    	           	header: '计划市级人数',
    	           	dataIndex: 'contrastCityValue',
    	               minWidth: 90,
    	               flex: 1,
    	               align: "center",
    	               sortable: false,
    	       		renderer: function(value, metaData, record){
    	       			if(!record.get("contrastCityState")){
    	       				metaData.style = "color:red;";
    	       			}
    	       			return value;
    	       		}
    	           },{
    	           	header: '计划县级人数',
    	           	dataIndex: 'contrastCountyValue',
    	               minWidth: 90,
    	               flex: 1,
    	               align: "center",
    	               sortable: false,
    	       		renderer: function(value, metaData, record){
    	       			if(!record.get("contrastCountyState")){
    	       				metaData.style = "color:red;";
    	       			}
    	       			return value;
    	       		}
    	           },{
    	           	header: '计划总人数',
    	           	dataIndex: 'contrastCountValue',
    	               minWidth: 90,
    	               flex: 1,
    	               align: "center",
    	               sortable: false,
    	       		renderer: function(value, metaData, record){
    	       			if(!record.get("contrastCountState")){
    	       				metaData.style = "color:red;";
    	       			}
    	       			return value;
    	       		}
    	           }];
    	}
    	this.columns = columns;
    	
        this.store = Ext.create('PJ.'+ prototype +'.trainingprogram.ParticipantsNumList',{
        	isLoad: false
        });
        this.plugins = [Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit: 1
        })];
        this.callParent(arguments);
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
    },
    listeners: {
		viewready: function(){
			var me = this;
			var store = this.store;
            var params = store.proxy.extraParams;
            var newParams = {
            		searchPlanId: me.up("window").planId,
            		//searchPlanId: '8a10e7f555e26ad70155e323806700d2',
            		searchApplyPlan: 1
            };
            var re = null;
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load({
                scope: this,
                callback: function(records, operation, success) {
                    var reArray = new Array();
                    for(i in records){
                    	var newObject = {
                    			contrastCityValue: records[i].get("contrastCityValue"),
                    			contrastCountyValue: records[i].get("contrastCountyValue"),
                    			contrastCountValue: records[i].get("contrastCountValue")
                    	};
                    	reArray.push(newObject);
                    }
                    me.res = reArray;
                }
            });
            // 触发权限过滤事件
            me.fireEvent("permission", this);
		}
    }
});
